<?php
declare(strict_types=1);
namespace cms\system\admin\api_controller;

use Hyperf\Di\Annotation\Inject;
use Hyperf\Contract\ContainerInterface;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;

abstract class AbstractController {
    /**
     * @Inject()
     * @var ContainerInterface
     */
    protected ContainerInterface $container;

    /**
     * @Inject()
     * @var RequestInterface
     */
    protected RequestInterface $request;

    /**
     * @Inject()
     * @var ResponseInterface
     */
    protected ResponseInterface $response;

    protected function success($message = 'success', $data = []): \Psr\Http\Message\ResponseInterface
    {
        $result = [
            'code' => 1,
            'msg'  => $message,
            'data' => $data,
        ];
        return $this->response->json($result);
    }

    protected function error($message = '', $code = 0): \Psr\Http\Message\ResponseInterface
    {
        return $this->response->json([
            'code' => $code,
            'msg' => $message
        ]);
    }
}